package com.xxxx.server.controller;


import com.xxxx.server.pojo.Department;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.service.IDepartmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-10-15
 */
@RestController
@RequestMapping("/system/basic/department")
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    @ApiOperation(value = "查询所有部门")
    @GetMapping("/")
    public List<Department> getAll(){
        return departmentService.getAll();
    }

    @ApiOperation(value = "添加部门")
    @PostMapping("/")
    public RespBean save(@RequestBody Department dep){
        System.out.println("insert....");
        departmentService.insert(dep);
        return RespBean.success("添加成功");
    }

    @ApiOperation(value = "删除部门")
    @DeleteMapping("/{id}")
    public RespBean delete(@PathVariable("id") int id){
        departmentService.removeById(id);
        return RespBean.success("删除成功");
    }

}
